﻿// 2-4 行列式的计算 (20分).cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
/*
date:20200402 pm23 17
user:Dongcheng Li
key:1.数字字符到整形直接减48
	2.行列式的计算，下标：行下标不变，列下标全排列，并根据逆序数决定本次累乘的正负号
*/

#include <iostream>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;
int nishunxudui(string a)
{
	int count = 0;
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = i + 1; j < a.size(); j++)
		{
			if (i < j && a[i] > a[j])
			{
				count++;
			}
		}

	}
	return count;
}
int liancheng(string a)
{
	int count = 1;
	for (int i = 0; i < a.size(); i++)
	{
		count =(int(a[i])-48)* count;
	}
	return count;
}
int main()
{
	int n, k,h,l , j,distance,i, p;
	queue<int>position;
	int ex_count = 0;
	string input="";
	string put = "";
	int re = 0;
	int ji = 1;
	cin >> n ;

	//cin >> input;
	int* e = new int[n ];
	int** a = new int* [n];

	for (i = 0; i < n; i++)
	{
		a[i] = new int[n];
	}
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < n; j++)
		{
			cin>>a[i][j];
		}
	}
	for (k= n; k > 0;k--)
	{
		input.insert(0, to_string(k));
	}

	sort(input.begin(), input.end());

	/*for (i = 0; i < n; i++)
	{
		ji= ji* a[i][int(input[i])-48-1];
		//cout << ji << endl;
	}


	if (nishunxudui(input)%2==0)
	{
		//zheng
		re = re + ji;
	}
	else
	{
		re = re - ji;
	}*/
	do {
		{
			ji = 1;
			for (i = 0; i < n; i++)
			{
				ji = ji * a[i][int(input[i]) - 48 - 1];
				//cout << ji << endl;
			}

			if (nishunxudui(input) % 2 == 0)
			{
				//zheng
				re = re + ji;
			}
			else
			{
				re = re - ji;
			}

		}
	} while (next_permutation(input.begin(), input.end()));

	cout << re ;
}

